/**
 *  This function is only used for monitoring input sets of text type when the value changed.
 *	@name watch
 *  @summary Monitoring input(type:text) when the value changed
 *  @author [Leon Linn](http://www.mxinghuo.com)
 *  @deprecated
 *
 *  @param {currentVal} changed text to be return
 *  @param {currentNode} the target element
 *  
 *  @example
 *  $(iconDisplayClass).watch(function(value, e){
		var arrayChangedName, isExisting = false,
			idTextChanged = $(e).closest("li").attr("data-id");
		
		for (var i=0; i< arrayChangedName.length;i++){
			if ( idTextChanged == arrayChangedName[i][0]){
				arrayChangedName[i][1] = value;
				//set isExisting to true if this value already existing in arrayChangedName
				isExisting = true;
				break;
			}
		}
		if (!isExisting){
			arrayChangedName.push([idTextChanged,value]);
			isExisting = false;
		}
	});
 * 
 */
(function($) {  
	//watch() is used for input:text to monitor if the value is changed
	$.fn.watch = function(callback) {  
	  return this.each(function() {  
			//save the value before 
			$.data(this, 'originVal', $(this).val());  

			//if the value is changed, then return the value, else the return value is null
			$(document).on('blur', "input:text", function() {
				//fix bug: combobox and combotree don't trigger this function
				if (!($(this).hasClass("combo-text"))) {
					var originVal = $.data(this, 'originVal').trim(),
						currentVal = $(this).val().trim(); 

					 if (originVal !== currentVal) {  
						  $.data(this, 'originVal', currentVal);
						  callback(currentVal, this); 
					 }  	
				}
			});  
			//if the value is changed, then return the value, else the return value is null
			$(document).on('blur', "textarea", function() {
				var originVal = $.data(this, 'originVal').trim(),
					currentVal = $(this).val().trim(); 

				 if (originVal !== currentVal) {  
					  $.data(this, 'originVal', currentVal);
					  callback(currentVal, this); 
				 }  	
			});  
	  });  
	}  
})(jQuery);  